package com.chen.service.impl;

import com.chen.api.IAccountADubboService;
import com.chen.api.IAccountBDubboService;
import com.chen.dto.AccountA;
import com.chen.exception.MyRpcException;
import com.chen.service.BusinessService;
import org.dromara.hmily.annotation.HmilyTCC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;

@Service
public class BusinessServiceImpl implements BusinessService {

    @Autowired
    private IAccountADubboService accountADubboService;

    @Autowired
    private IAccountBDubboService accountBDubboService;

    @Override
    @HmilyTCC(confirmMethod = "confirmConvert",cancelMethod = "cancelConvert")
    public void convert(int userId, BigDecimal dollar, BigDecimal rmb) throws MyRpcException {
        accountADubboService.dollarToRmb(userId,dollar);
        accountBDubboService.rmbToDollar(userId,rmb);
    }

    private void confirmConvert(int userId, BigDecimal dollar, BigDecimal rmb) {
        System.out.println("兑换成功。。。");
    }

    private void cancelConvert(int userId, BigDecimal dollar, BigDecimal rmb) {
        System.out.println("兑换失败。。。");
    }
}
